package win.devhu.onestation;

import com.google.inject.Guice;

import io.javalin.Javalin;
import io.javalin.plugin.openapi.OpenApiOptions;
import io.javalin.plugin.openapi.OpenApiPlugin;
import io.javalin.plugin.openapi.ui.SwaggerOptions;
import io.swagger.v3.oas.models.info.Info;
import win.devhu.onestation.app.Application;
import win.devhu.onestation.app.ApplicationModule;

public class AppLauncher {

	private static final int PORT = 2312;

	public static void main(String[] args) {
		Javalin app = Javalin.create(config ->{
			config.addStaticFiles("static");
			config.registerPlugin(new OpenApiPlugin(getOpenApiOptions()));
		}).start(PORT);
		Guice.createInjector(new ApplicationModule(app)).getInstance(Application.class).start();
	}
	
	/**
	 * swagger 文档配置 
	 * @return
	 */
	public static OpenApiOptions getOpenApiOptions() {
	    Info applicationInfo = new Info()
	        .version("1.0")
	        .description("OneStation");
	    return new OpenApiOptions(applicationInfo)
	    		.path("/swagger-docs")
	    		.activateAnnotationScanningFor("win.devhu.onestation.controller")
	    		.swagger(new SwaggerOptions("/swagger").title("OneStation 接口文档"));
	}

}
